package com.base.commonlib.sp;

import android.content.Context;
import android.content.SharedPreferences;

import com.base.commonlib.base.BaseApp;

import java.util.Set;


/**
 * Created by arvin on 2018/10/26.
 */

public class SpUtil {
    private  static SharedPreferences sConfig = BaseApp.sAppContext.getSharedPreferences("Config", Context.MODE_PRIVATE);

    private static final String FIRSTRUN="firstRun";
    private static final String USER_ACCOUNT="account";
    private static final String USER_ACCOUNT_ARRAY="account_array";
    private static final String USER_PW="passwords";

    private static final String TOKEN = "token";

    private static final String RTSP_TOKEN = "rtsp_token";


    private static final String ROAD_VERSION = "road_version";



    private static final String PARTEN_ID = "parent_id";//搭档ID
    private static final String PARTEN_NAME = "parent_name";//搭档姓名


    public static final String VIDEO_SETTING = "video_setting";


    public static final String CENTER_IMG = "center_img";

    public static final String REMMBER_PWD = "remmber_pwd";


    public static void setRemmberPwd(boolean isRemmber){
        putBoolean(REMMBER_PWD,isRemmber);
    }

    public static boolean getRemmberPwd(){
        return getBoolean(REMMBER_PWD,true);
    }


    public static void setIsFirstRun()
    {
        putBoolean(FIRSTRUN,false);
    }

    public static boolean getIsFirstRun()
    {
        return getBoolean(FIRSTRUN,true);
    }

    public static void setUserAccount(String account)
    {
        putString(USER_ACCOUNT,account);
    }


    public static void setUserAccountList(Set<String> accounts)
    {
        putStringSet(USER_ACCOUNT_ARRAY,accounts);
    }


    public static String getUserAccount()
    {
        return getString(USER_ACCOUNT);
    }

    public static void setUserPw(String pw)
    {
        putString(USER_PW,pw);
    }

    public static String getUserPw()
    {
        return getString(USER_PW);
    }

    public static void setToken(String token){
        putString(TOKEN,token);
    }
    public static void setRtspToken(String token){
        putString(RTSP_TOKEN,token);
    }
    public static String getToken(){
        return getString(TOKEN);
    }
    public static String getRtspToken(){
        return getString(RTSP_TOKEN);
    }
    public static void setCenterImg(String centerImg){
        putString(CENTER_IMG,centerImg);
    }

    public static String getCenterImg(){
        return getString(CENTER_IMG);
    }

    public static void putString(String key, String vale)
    {
        SharedPreferences.Editor editor = sConfig.edit().putString(key, vale);
        editor.commit();
    }
    public static void putStringSet(String key, Set<String> values)
    {
        SharedPreferences.Editor editor = sConfig.edit().putStringSet(key, values);
        editor.commit();
    }

    public static void putBoolean(String key, Boolean b)
    {
        SharedPreferences.Editor editor = sConfig.edit().putBoolean(key, b);
        editor.commit();
    }

    public static void putInt(String key, int i)
    {
        SharedPreferences.Editor editor = sConfig.edit().putInt(key, i);
        editor.commit();
    }


    public static String getString(String key)
    {
        return sConfig.getString(key, "");
    }
    public static Set<String> getStringSet(Set<String> defValues)
    {
        return sConfig.getStringSet(USER_ACCOUNT_ARRAY, defValues);
    }

    public static Boolean getBoolean(String key)
    {
        return sConfig.getBoolean(key,false);
    }

    public static Boolean getBoolean(String key, boolean def)
    {
        return sConfig.getBoolean(key,def);
    }



    public static int getInt(String key, int def)
    {
        return sConfig.getInt(key,def);
    }

    public static void setRoadVersion(String version){
        putString(ROAD_VERSION,version);
    }

    public static String getRoadVersion(){
        return getString(ROAD_VERSION);
    }
}
